//
//  CellOfDetailsPageDiscountSearchResult.m
//  FreeTravel
//
//  Created by 徐康 on 16/9/2.
//  Copyright © 2016年 KX. All rights reserved.
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "CellOfDetailsPageDiscountSearchResult.h"
@interface CellOfDetailsPageDiscountSearchResult ()
@property (nonatomic, strong) UILabel *labelOfTitle;
@property (nonatomic, strong) UILabel *labelOfPrice;
@property (nonatomic, strong) UILabel *labelOfLastminute_des;
@property (nonatomic, strong) UILabel *labelOfDepartureTime ;

@property (nonatomic, strong) UIImageView *imageViewOfPhoto;
@property (nonatomic, strong) UIView *orangeView;
@end
@implementation CellOfDetailsPageDiscountSearchResult
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.orangeView = [[UIView alloc]init];
        self.imageViewOfPhoto = [[UIImageView alloc]init];
        self.labelOfTitle = [[UILabel alloc]init];
        self.labelOfDepartureTime = [[UILabel alloc]init];
        self.labelOfPrice = [[UILabel alloc]init];
        self.labelOfLastminute_des = [[UILabel alloc]init];
        
        [self.contentView addSubview:self.orangeView];
        
        [self.contentView addSubview:_labelOfTitle];
        [self.contentView addSubview:self.labelOfDepartureTime];
        [self.contentView addSubview:self.labelOfPrice];
        [self.contentView addSubview:self.labelOfLastminute_des];
        [self.contentView addSubview:self.imageViewOfPhoto];
    }
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.imageViewOfPhoto mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.contentView);
        make.height.mas_offset(100);
        
    }];
    [self.orangeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.contentView);
        make.height.mas_offset(2);
        make.top.equalTo(self.imageViewOfPhoto.mas_bottom);
    }];
    self.orangeView.backgroundColor = [UIColor orangeColor];
    [self.labelOfTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.orangeView.mas_bottom).mas_offset(20);
        make.bottom.equalTo(self.labelOfDepartureTime.mas_top).mas_offset(-20);
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
    }];
    self.labelOfTitle.numberOfLines = 0;
    [self.labelOfDepartureTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.bottom.equalTo(self.labelOfLastminute_des.mas_top).mas_offset(-20);
        make.height.mas_equalTo(10);
        make.width.mas_equalTo(100);
    }];
    self.labelOfDepartureTime.textColor = [UIColor grayColor];
    self.labelOfDepartureTime.font = [UIFont systemFontOfSize:12];
    [self.labelOfLastminute_des mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).mas_offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.height.mas_equalTo(10);
        make.width.mas_equalTo(80);
    }];
    self.labelOfLastminute_des.textColor = [UIColor grayColor];
    self.labelOfLastminute_des.font = [UIFont systemFontOfSize:12];
    [self.labelOfPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
        make.height.mas_offset(10);
        make.width.mas_offset(80);
    }];
    
    self.labelOfPrice.textColor = [UIColor redColor];
    self.labelOfPrice.font = [UIFont systemFontOfSize:15];
    
}
- (void)setModel:(ModelOfDiscountSpecificSearchResult *)model{
    _model = model;
    NSRange range = NSMakeRange(4, model.price.length-11);
    model.price = [model.price substringWithRange:range];
    NSString *str = [NSString stringWithFormat:@"%@元起",model.price];
    self.labelOfPrice.text = str;
    self.labelOfTitle.text = model.title;
    self.labelOfDepartureTime.text = model.departureTime;
    self.labelOfLastminute_des.text = model.lastminute_des;
    
    [self.imageViewOfPhoto sd_setImageWithURL:[NSURL URLWithString:model.pic]];
}
@end
